<?php

/**
 * This is the model class for table "tbtt_user".
 *
 * The followings are the available columns in table 'tbtt_user':
 * @property integer $use_id
 * @property string $use_username
 * @property string $use_password
 * @property string $use_salt
 * @property string $use_email
 * @property string $use_fullname
 * @property integer $use_birthday
 * @property integer $use_sex
 * @property string $use_address
 * @property integer $use_province
 * @property string $use_phone
 * @property string $use_mobile
 * @property string $use_yahoo
 * @property string $use_skype
 * @property integer $use_group
 * @property integer $use_status
 * @property integer $use_regisdate
 * @property integer $use_enddate
 * @property string $use_key
 * @property string $use_lastest_login
 * @property integer $use_role
 */


class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
         public $use_password_repeat;
         public $verifyCode;
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbtt_user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('use_username, use_password, use_email', 'required'),
			array('use_birthday, use_sex, use_province, use_group, use_status, use_regisdate, use_enddate, use_role', 'numerical', 'integerOnly'=>true),
			array('use_username, use_password', 'length', 'max'=>35),
			array('use_salt', 'length', 'max'=>10),
			array('use_email, use_yahoo, use_skype', 'length', 'max'=>50),
			array('use_fullname, use_address', 'length', 'max'=>100),
			array('use_phone, use_mobile', 'length', 'max'=>20),
			array('use_key', 'length', 'max'=>150),
			array('use_lastest_login', 'safe'),
                        array('use_password','compare'),    
                        array('use_password_repeat', 'safe'),
                        
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('use_id, use_username, use_password, use_salt, use_email, use_fullname, use_birthday, use_sex, use_address, use_province, use_phone, use_mobile, use_yahoo, use_skype, use_group, use_status, use_regisdate, use_enddate, use_key, use_lastest_login, use_role', 'safe', 'on'=>'search'),
                          array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements())
             );
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
        

        
        
	public function attributeLabels()
	{
		return array(
			'use_id' => 'Use',
			'use_username' => 'Use Username',
			'use_password' => 'Password',
			'use_password_repeat' => 'Password Repeat',                    
			'use_salt' => 'Use Salt',
			'use_email' => 'Use Email',
			'use_fullname' => 'Use Fullname',
			'use_birthday' => 'Use Birthday',
			'use_sex' => 'Use Sex',
			'use_address' => 'Use Address',
			'use_province' => 'Use Province',
			'use_phone' => 'Use Phone',
			'use_mobile' => 'Use Mobile',
			'use_yahoo' => 'Use Yahoo',
			'use_skype' => 'Use Skype',
			'use_group' => 'Use Group',
			'use_status' => 'Use Status',
			'use_regisdate' => 'Use Regisdate',
			'use_enddate' => 'Use Enddate',
			'use_key' => 'Use Key',
			'use_lastest_login' => 'Use Lastest Login',
			'use_role' => 'Use Role',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('use_id',$this->use_id);
		$criteria->compare('use_username',$this->use_username,true);
		$criteria->compare('use_password',$this->use_password,true);
		$criteria->compare('use_salt',$this->use_salt,true);
		$criteria->compare('use_email',$this->use_email,true);
		$criteria->compare('use_fullname',$this->use_fullname,true);
		$criteria->compare('use_birthday',$this->use_birthday);
		$criteria->compare('use_sex',$this->use_sex);
		$criteria->compare('use_address',$this->use_address,true);
		$criteria->compare('use_province',$this->use_province);
		$criteria->compare('use_phone',$this->use_phone,true);
		$criteria->compare('use_mobile',$this->use_mobile,true);
		$criteria->compare('use_yahoo',$this->use_yahoo,true);
		$criteria->compare('use_skype',$this->use_skype,true);
		$criteria->compare('use_group',$this->use_group);
		$criteria->compare('use_status',$this->use_status);
		$criteria->compare('use_regisdate',$this->use_regisdate);
		$criteria->compare('use_enddate',$this->use_enddate);
		$criteria->compare('use_key',$this->use_key,true);
		$criteria->compare('use_lastest_login',$this->use_lastest_login,true);
		$criteria->compare('use_role',$this->use_role);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        /*
        public function afterValidate(){
            parent::afterValidate();
            $this->use_password = $this->encrypt($this->use_password);
        }
        
        public function encrypt($value){
            
            return md5($value);
            
        }
       */
}